﻿package  {
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	
	public class ChestBlock extends Obstacle {
		
		private var empty:Boolean;
		private var chestID:int;
		private var active:Boolean;
		var _player:Player;
		
		
		public function ChestBlock(aX:Number,aY:Number,aWidth:Number,aHeight:Number, aChest:int,aPlayer:Player) {
			// constructor code
			super(aX,aY,aWidth,aHeight);
			chestID = aChest;
			empty = false;
			_player = aPlayer;
			this.addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
			
		}
		private function onAddedToStage(e:Event){
			gotoAndStop(3);
		}
		
		override public function CollisionCheck(locX:int, locY:int):Boolean{
			//trace("" + hitTestPoint(locX,locY));
			
			

			
			if(active == true)
			{
				if(!empty)
				{
					gotoAndStop(0);
				}
				if(hitTestPoint(locX,locY) && !empty)
				{
					switch(chestID)
					{
						case 0:
						_player.MyKey = true;
						trace("GOT KEY");
						break;
						case 1:
						//dungeon map
						trace("GOT MAP(not really)");
						break;
					
						case 2:
						_player.HasSpring = true;
						trace("GOT SPRING, PRESS V TO USE");
						break;
					
						case 3:
						_player.MyKey = true;
						trace("GOT KEY");
						break;
					
						case 4:
						_player.BigKey = true;
						trace("GOT BIG KEY");
						break;
					}
					empty = true;
					this.nextFrame();
				}
				
				return hitTestPoint(locX,locY);
			}
			else
			{
				switch(chestID)
				{
					case 0:
					if(_player.Switch1 == true)
					{
						active = true;
					}
					break;
					case 1:
					if(_player.Switch2 == true)
					{
						active = true;
					}
					break;
					
					case 2:
					if(_player.Switch3 == true)
					{	
						active = true;
					}
					break;
					
					case 3:
					if(_player.Switch4 == true)
					{
						active = true;
					}
					break;
					
					case 4:
					active = true;
					break;
				}
			}
			
			return false;
			
		}
	}
	
}

